package com.ybkj.o2o.zhuanche.controller;

import com.google.common.base.Preconditions;

import com.ybkj.o2o.zhuanche.common.DataGrid;
import com.ybkj.o2o.zhuanche.common.query.OrderRefuseQuery;
import com.ybkj.o2o.zhuanche.common.transport.Result;
import com.ybkj.o2o.zhuanche.entity.OrderRefuse;
import com.ybkj.o2o.zhuanche.manager.OrderRefuseManager;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("api/orderRefuse")
public class OrderRefuseRes {

  @Autowired
  private OrderRefuseManager orderRefuseManager;
  
  /**
   * 查询拒单记录.
   * @param companyId 公司id
   * @param param 模糊查询参数
   * @param page 分页参数
   * @param rows 分页参数
   */
  
  @RequestMapping(value = "findRefuses", method = RequestMethod.GET)
  public ResponseEntity<Object> findRefuses(
      @RequestParam(required = false, value = "companyId") Long companyId,
      @RequestParam(required = false, value = "param") String param,
      @RequestParam("page") Integer page,
      @RequestParam("rows") Integer rows,
      @RequestParam("appKey") String appKey) {
    ResponseEntity<Object> responseEntity = null;
    Preconditions.checkArgument(StringUtils.isNotBlank(appKey), "AppKey不能为空");
    
    OrderRefuseQuery orderRefuseQuery = new OrderRefuseQuery();
    orderRefuseQuery.setCompanyId(companyId);
    orderRefuseQuery.setPage(page);
    orderRefuseQuery.setRows(rows);
    orderRefuseQuery.setAppKey(appKey);
    
    try {
      DataGrid<OrderRefuse> dataGrid = orderRefuseManager.findByParam(orderRefuseQuery);

      Result<DataGrid<OrderRefuse>> result = new Result<DataGrid<OrderRefuse>>(0, "成功", dataGrid);

      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;
    } catch (Exception ex) {
      ex.printStackTrace();
      Error error = new Error("内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }
  }

}
